package com.zbxx.container.websocket.repository;

import com.zbxx.container.websocket.entity.User;

import org.springframework.data.domain.Example;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.repository.query.QueryByExampleExecutor;


import java.util.List;

/**
 * @author 万仁杰
 * @date 2019/05/21
 */

public interface JpaUserRepository extends CrudRepository<User, Integer>, JpaSpecificationExecutor<User>, QueryByExampleExecutor {

    /**
     * 根据账号查找
     *
     * @param account
     * @return
     */
    @EntityGraph("user.graph")
    User findByAccount(String account);

    @Query("select count(u) from User u where u.account in ?1")
    int findLikeAccount(List<String> accounts);

    /**
     * 结果集处理 应该只对 nameMethod有效
     */
    // @Value("#{T(java.util.Arrays).toString(target)}")
    @Query(value = "select u from User u where u.account = :#{#user.account}")
    List<User> getUsersByUserInfo(@Param("user") User user);


    @Override
    @EntityGraph("user.graph")
    Iterable findAll(Example example);
}
